package com.bangyu.monitor.modular.system.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
 * @Auther: zhangxue
 * @Date: 19/4/13 16:29
 * @Description:
 */
@Data
@TableName("sys_mqtt_topic")
public class MqttTopic {

    private Long id;
    private String topic;
    private Integer qos;

    private Integer type;
    private Integer status;


    //根据设备编码获取设备类型
    public static Integer getTypeByDeviceNo(List<MqttTopic> list, String deviceNo){
        if(StringUtils.isBlank(deviceNo) || CollectionUtils.isEmpty(list)){
            return 1;
        }
        Integer type = null;
        for(MqttTopic mqttTopic:list){
            String topic = mqttTopic.getTopic();
            if(StringUtils.isNotBlank(topic)){
                if(topic.indexOf(deviceNo)>0){
                    type = mqttTopic.getType();
                    break;
                }
            }
        }
        return type;

    }
}
